package models;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;

import play.data.validation.Required;
import play.db.jpa.Model;

@Entity
public class DietInformation extends Model {

	public Integer age;
	public Integer height;
	public Integer weight;
	public Boolean isMale;

	/**
	 * Predefined amount of calories the user wants to consume
	 */
	@Required
	public int targetCalories;

	
	public Double sportProfile;

	public DietInformation(int age, int height, int weight, boolean isMale, double sportProfile){
		this.age = age;
		this.height = height;
		this.weight = weight;
		this.isMale = isMale;
		this.sportProfile = sportProfile;

		this.calculateTargetCalories();
		this.save();
	}

	private void calculateTargetCalories() {
		int basicMetabolicRate = 0;
				
		//formula for men: 66,47 + (13,7 * weight [kg]) + (5 * height [cm]) – (6,8 * age [years])
		if (isMale){
			basicMetabolicRate = (int) (66.47 + (13.7 * this.weight) + (5 * this.height) - (6.8 * this.age));
		}
		//formula for women: 655,1 + 9,6 × weight [kg] + 1,8 × height [cm] − 4,7 × age [years]
		else{
			basicMetabolicRate = (int) (655.1 + (9.6 * this.weight) + (1.8 * this.height) - (4.7 * this.age));
		}
				
		this.targetCalories =  (int) (basicMetabolicRate * this.sportProfile);
	}

	public DietInformation(int targetCalories){
		this.targetCalories = targetCalories;
		this.save();
	}
}
